Allow overriding the OPL metadata release API URL via an environment variable#3057
Allow overriding the OPL metadata release API URL via an environment variable#3057xcompass wants to merge 1 commit into
Conversation
drgrice1
left a comment
There was a problem hiding this comment.
It is questionable if this should be accepted. Should we support using external repositories for the OPL? Those that are maintaining these repositories should submit their problems to the actual OPL instead. There are other methods for using external libraries for problems that can be used.
This will need discussion.
| # Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL, | ||
| # for example, for sites that use a fork of the OPL. | ||
| my $releaseApiUrl = $ENV{OPL_METADATA_RELEASE_API_URL} | ||
| // 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest'; | ||
| my $releaseDataFF = File::Fetch->new(uri => $releaseApiUrl); | ||
| my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error; | ||
| my $path = Mojo::File->new($file); | ||
| my $releaseData = decode_json($path->slurp); |
There was a problem hiding this comment.
Please change this to
| # Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL, | |
| # for example, for sites that use a fork of the OPL. | |
| my $releaseApiUrl = $ENV{OPL_METADATA_RELEASE_API_URL} | |
| // 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest'; | |
| my $releaseDataFF = File::Fetch->new(uri => $releaseApiUrl); | |
| my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error; | |
| my $path = Mojo::File->new($file); | |
| my $releaseData = decode_json($path->slurp); | |
| # Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL, | |
| # for example, for sites that use a fork of the OPL. | |
| my $releaseDataFF = File::Fetch->new(uri => $ENV{OPL_METADATA_RELEASE_API_URL} | |
| // 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest'); | |
| my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error; | |
| my $path = Mojo::File->new($file); | |
| my $releaseData = decode_json($path->slurp); |
There is no need for the intermediate $releaseApiUrl variable that is only used once. Just put its value in the one place it is used.
There was a problem hiding this comment.
Done — applied your suggestion; the $ENV{OPL_METADATA_RELEASE_API_URL} // ... default is now inlined in the File::Fetch->new call with no intermediate variable.
|
We have instructors who are not conformable sharing their libraries publicly. So we have to host our own repo. For those are OK with sharing, we let them open PRs to the OPL directly. |
The download-OPL-metadata-release.pl script hardcodes the GitHub API URL used to locate the latest OPL metadata release. Sites that maintain a fork of the webwork-open-problem-library (for example, with local problem metadata) cannot use the script to download their own metadata releases. Allow the URL to be overridden by setting the OPL_METADATA_RELEASE_API_URL environment variable, and fall back to the existing openwebwork URL when the variable is not set. The rest of the fetch and restore logic is unchanged.
0d87deb to
a50909b
Compare
Summary
bin/download-OPL-metadata-release.plhardcodes the GitHub API URL used to locate the latest OPL metadata release (https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest). Sites that maintain a fork of the webwork-open-problem-library (for example, to carry local problems and publish their own metadata releases) cannot use the script against their fork without patching it.This change allows the release API URL to be overridden by setting the
OPL_METADATA_RELEASE_API_URLenvironment variable:When the variable is not set, the script behaves exactly as before, using the openwebwork URL. The rest of the fetch/decode/restore logic is untouched, and a brief comment documents the override at the point of use.
Testing
perltidyv20260204 (the version pinned in.github/workflows/check-formats.yml) with the repository.perltidyrc; the committed file is idempotent under it.perl -cpasses on the full script (checked with the script's WeBWorK/Helper module dependencies stubbed, since compiling those requires a full runtime environment).Dependencies: none.